package com.mingmen.supplier.adapter;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.mingmen.supplier.R;
import com.mingmen.supplier.defineview.GlideRoundTransform;
import com.mingmen.supplier.defineview.PhotoDialog;
import com.mingmen.supplier.httpconfig.AppConfig;
import com.mingmen.supplier.jingli.JingLiRuRightAdapter;
import com.mingmen.supplier.model.CancelModel;
import com.mingmen.supplier.model.JingLiRukuModel;
import com.mingmen.supplier.model.MySimpleData;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by yjwfn on 17-9-23.
 */

public class CanCelOrderAdapter extends RecyclerView.Adapter<CanCelOrderAdapter.PhotoViewHolder> {


    Context context;
    List<CancelModel.DataBean.CancelDetailBean> myList;

    private String img1 = "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3933355596,669391437&fm=26&gp=0.jpg";
    private String img2 = "http://img4.imgtn.bdimg.com/it/u=1445674920,12445384&fm=26&gp=0.jpg";
    private String img3 = "http://img4.imgtn.bdimg.com/it/u=482593725,2192787331&fm=26&gp=0.jpg";
    private String img4 = "http://img5.imgtn.bdimg.com/it/u=2306608262,3534874273&fm=26&gp=0.jpg";
    private String img5 = "http://img3.imgtn.bdimg.com/it/u=1827863856,2661023953&fm=26&gp=0.jpg";
    private String img6 = "http://img0.imgtn.bdimg.com/it/u=2775335106,966369936&fm=26&gp=0.jpg";
    private String img7 = "http://img4.imgtn.bdimg.com/it/u=1881496596,2607061598&fm=26&gp=0.jpg";
    private String img8 = "http://img2.imgtn.bdimg.com/it/u=3129434724,2523766044&fm=26&gp=0.jpg";
    private String img9 = "http://img0.imgtn.bdimg.com/it/u=1199886885,3035315889&fm=26&gp=0.jpg";
    private OnitemClick onitemClick;   //定义点击事件接口

    public void setCallBack(OnitemClick callBack) {
        this.onitemClick = callBack;
    }

    public CanCelOrderAdapter(Context context, List<CancelModel.DataBean.CancelDetailBean> myList) {
        this.context = context;
        this.myList = myList;
    }

    public void setDataList(List<CancelModel.DataBean.CancelDetailBean> myList) {
        this.myList = myList;

        notifyDataSetChanged();

    }

    @Override
    public PhotoViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        return new PhotoViewHolder(inflater.inflate(R.layout.itemcancelorder, parent, false));
    }

    @Override
    public void onBindViewHolder(PhotoViewHolder holder, int position) {
        CancelModel.DataBean.CancelDetailBean cancelDetailBean = myList.get(position);
        List<String> second = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            second.add("ITem" + i);
        }

        holder.cancelReason.setText(cancelDetailBean.getCancelReason());

        List<MySimpleData> datas = new ArrayList<>();
        ArrayList<String> imageData = new ArrayList<>();
     /*   MySimpleData data = new MySimpleData();
        data.setTitle("秒速5厘米");
        imageData.add(img1);
        imageData.add(img2);
        imageData.add(img3);
        imageData.add(img4);*/

        for (int i = 0; i < myList.size(); i++) {
            imageData.add(myList.get(i).getPicture());
        }
//        data.setImgs(imageData);

//        datas.add(0, imageData);

        if (holder.photoWaiAdapter == null) {
            holder.photoWaiAdapter = new PhotoCancelAdapter(context);
            LinearLayoutManager layoutManage = new LinearLayoutManager(context);
            holder.rv_item.setLayoutManager(layoutManage);
//            holder.rvItemItem.addItemDecoration(new GridSpacingItemDecoration(2, 20, false));
            holder.rv_item.setAdapter(holder.photoWaiAdapter);

//            holder.photoWaiAdapter.setData(datas);
            holder.photoWaiAdapter.setData(datas);
        } else {
//            holder.photoWaiAdapter.setPosition(position);
            holder.photoWaiAdapter.notifyDataSetChanged();
        }
        holder.photoWaiAdapter.setCallBack(new PhotoCancelAdapter.OnMyAdapterCallBack() {
            @Override
            public void onItemClick(int position, ArrayList<String> itemImgs) {

            }
        });

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onitemClick.onItemClick(v, position, holder.getAdapterPosition(), second, datas,myList);
            }
        });
        Glide.with(context).load(AppConfig.IMGURL + cancelDetailBean.getPicture()).dontAnimate().placeholder(R.mipmap.zhanwei).error(R.mipmap.zhanwei).transform(new GlideRoundTransform(context, 5)).into(holder.ivAvatar);
    }

    @Override
    public int getItemCount() {
        return myList.size();
    }

    static final class PhotoViewHolder extends RecyclerView.ViewHolder {


        RecyclerView rv_item;
        CancelPhotoAdapter chuShiRightAdapter;
        PhotoCancelAdapter photoWaiAdapter;
        TextView cancelReason;
        ImageView ivAvatar;

        public PhotoViewHolder(View itemView) {
            super(itemView);

            rv_item = itemView.findViewById(R.id.rv_item);
            cancelReason = itemView.findViewById(R.id.cancelReason);
            ivAvatar= itemView.findViewById(R.id.ivAvatar);
        }
    }

    //定义一个点击事件的接口
    public interface OnitemClick {
        void onItemClick(View view, int parentPosition, int position, List<String> mList, List<MySimpleData> datas,List<CancelModel.DataBean.CancelDetailBean> myList);
    }

    //定义设置点击事件监听的方法
    public void setOnitemClickLintener(OnitemClick onitemClick) {
        this.onitemClick = onitemClick;
    }
}
